import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:lwtools/deleteApkPage.dart';
import 'package:lwtools/homePage.dart';

void main() {
  if (Platform.isMacOS) {
    // Enable macOS desktop support.
    WidgetsFlutterBinding.ensureInitialized();
    // Set the minimum window size.
    SystemChannels.platform.invokeMethod('Window.setMinSize', <String, dynamic>{
      'width': 400, // Set the minimum width.
      'height': 300, // Set the minimum height.
    });
  }

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: MyHomePage(
        title: '工具',
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Widget _currentPage = DeleteApkPage();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: _currentPage,
      drawer: MyDrawer((widget) {
        setState(() {
          _currentPage = widget;
        });
      }), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class MyDrawer extends StatelessWidget {
  MyDrawer(this.callback);

  Function? callback;

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        children: [
          ListTile(
            title: const Text('符号表上传'),
            onTap: () {
              // 处理点击 Item 1 的逻辑
              Navigator.pop(context);
              callback!(const HomePage());
            },
          ),
          ListTile(
            title: const Text('Apk delete'),
            onTap: () {
              // 处理点击 Item 2 的逻辑
              Navigator.pop(context);
              callback!(const DeleteApkPage());
            },
          ),
          // 添加其他列表项...
        ],
      ),
    );
  }
}
